#backtracking
import copy

class Solution(object):
    def combine(self, candidates, target, res, combination, begin):
        if target==0:
            res.append(copy.copy(combination))
            return
        for i in range(begin, len(candidates)):
            if target>=candidates[i]:
                combination.append(candidates[i])
                self.combine(candidates, target-candidates[i], res, combination, i)
                combination.pop()
    
    def combinationSum(self, candidates, target):
        res = []
        self.combine(candidates, target, res, [], 0)
        return res

print(Solution().combinationSum([2,3], 6))